package com.gxa.service.impl;

import com.gxa.dto.ResultDto;
import com.gxa.exception.SystemException;
import com.gxa.group.LoginPhone;
import com.gxa.mapper.UserMapper;
import com.gxa.pojo.User;
import com.gxa.service.UserService;
import com.gxa.util.Response;
import com.gxa.validator.MyValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpSession;

/**
 * @author 王康
 */
@Service("phoneService")
public class UserServiceSmsImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private MyValidator validator;

    @Override
    public ResultDto login(User user, HttpSession session) {
        validator.validate(user, LoginPhone.class);
        User dbUser = userMapper.findByPhone(String.valueOf(user.getUserPhone()));
        if (dbUser == null) {
            throw new SystemException(1003,"该用户不存在");
        }
        session.setAttribute("userName",dbUser.getUserName());
        session.removeAttribute("vcode");
        return Response.success(200,"登录成功");
    }
}
